﻿from django import forms
from django.forms import ModelForm
from models import Device, Equipment, Exhibition, History


class DeviceNewForm(ModelForm): 
    class Meta:
        model = Device
        exclude = ('location', 'verbose_location', 'exhibition',)

    def __init__(self, *args, **kwargs):
        super(DeviceNewForm, self).__init__(*args, **kwargs)

        
    def save(self, commit=True):
        self.cleaned_data['location'] = "str"
        self.cleaned_data['verbose_location'] = "Склад"
        self.cleaned_data['exhibition'] = None
        return super(DeviceNewForm, self).save(commit)



class DeviceMoveToExhibitionForm(forms.Form):
    exhibition = forms.ModelChoiceField(queryset=Exhibition.objects.filter(date_open__isnull=False), label='Выставка')
    comment = forms.CharField(required=False, label='Примечание', widget=forms.Textarea)
    
class DeviceMoveToExpositionForm(forms.Form):
    exposition = forms.ModelChoiceField(queryset=Exhibition.objects.filter(date_open__isnull=True), label='Зал')
    comment = forms.CharField(required=False, label='Примечание', widget=forms.Textarea)

class DeviceMoveToRepairForm(forms.Form):
    comment = forms.CharField(required=False, label='Примечание', widget=forms.Textarea)


class DeviceMoveToStorageForm(forms.Form):
    comment = forms.CharField(required=False, label='Примечание', widget=forms.Textarea)

'''
#CategoryForm = form_for_model(Category)
class CategoryForm(ModelForm): 
    class Meta:
        model = Category

#PartForm = form_for_model(Part)
class PartForm(ModelForm):
    class Meta:
        model = Part


class DocumentForm(ModelForm):
    class Meta:
        model = Document
        exclude = ('kind', 'user', 'state',)
        
    def __init__(self, author, kind, *args, **kwargs):
        super(DocumentForm, self).__init__(*args, **kwargs)
        self.author = author 
        self.kind = kind
        
    def save(self):
        self.cleaned_data['user'] = self.author
        self.cleaned_data['kind'] = self.kind
        self.cleaned_data['state'] = 'N'
        return super(DocumentForm, self).save()
 
        

class DocumentItemForm(ModelForm):
    class Meta:
        model = DocumentItem
        exclude = ('document', 'part',)

    def __init__(self, part_id, document, *args, **kwargs):
        super(DocumentItemForm, self).__init__(*args, **kwargs)
        self.part_id = part_id 
        self.doc = document
        
    def save(self, commit=True):
        self.cleaned_data['document'] = self.doc
        self.cleaned_data['part'] = self.part_id
        return super(DocumentItemForm, self).save(commit)
        
        
class DocumentReceiptForm(ModelForm):
    class Meta:
        model = DocumentReceipt
        exclude = ('document',)
        
    def __init__(self, document, *args, **kwargs):
        super(DocumentReceiptForm, self).__init__(*args, **kwargs)
        self.doc = document
        
    def save(self, commit=True):
        self.cleaned_data['document'] = self.doc
        return super(DocumentReceiptForm, self).save(commit)        
'''        
        
        
        
